if(/.*Mobile.*/.test(navigator.userAgent)){
	alert("WEB会议暂不支持手机浏览器,请改用电脑浏览器或者客户端登陆使用,谢谢!");
	window.location.href = "http://www.ccwe.com.cn/download/";
}
var Cnc;
if (!Cnc)
	Cnc = {};
if (!Cnc.Common)
	Cnc.Common = {};

Cnc.Common.DefaultDate = function(){
	var d, s = "";
	d = new Date();
	s += (d.getFullYear()< 10? "0"+d.getFullYear():d.getFullYear()) + "-";
	s += ((d.getMonth()+1)< 10? "0"+(d.getMonth()+1):(d.getMonth()+1)) + "-";
	return {
   		startDate:s + "01", 
   		endDate:s + (d.getDate()< 10? "0"+d.getDate():d.getDate()),
   		startTime:s + "01 00:00:00",
   		endTime:s + (d.getDate()< 10? "0"+d.getDate():d.getDate()) + " "+(d.getHours()< 10? "0"+d.getHours():d.getHours())+":"+(d.getMinutes()< 10? "0"+d.getMinutes():d.getMinutes())+":"+(d.getSeconds()< 10? "0"+d.getSeconds():d.getSeconds()),
   		minDate:"2012-08-01",
		maxDate:s + (d.getDate()< 10? "0"+d.getDate():d.getDate())
	};
};

Cnc.Common.recource = {
	user:{},
	requestUrl:"http://localhost:8080/deal/api/user/"
	//requestUrl:"http://172.16.21.211:8082/orgsynergy/services/synergy/web/json/"
};

Cnc.Common.confUserStatus = {		
	//会议呼叫状态
	20:"正在呼叫",
	21:"已接通",
	22:"用户正忙",
	23:"无人接听",
	24:"拒接接听",
	25:"用户挂断",
	26:"未呼叫",
	27:"正在呼叫",
	30:"未接通"
};

Cnc.Common.record = {
	name:null,
	number:null,
	faceImage:null
};

$(function(){
	var cnc_last_account = $.cookie("cnc_last_account");
	if(cnc_last_account){
		cnc_last_account = eval("("+cnc_last_account+")");

		if(cnc_last_account.token || cnc_last_account.autoLogin){
			
			Cnc.Common.recource.user.accessToken = cnc_last_account.token;
			ajax("getUserInfo",{
				success:function(dataResult){
					if(dataResult && dataResult.dataView){
						var user = dataResult.dataView.synergyStaff[0];
						$.extend(Cnc.Common.recource.user, user);
						
						$("#stuffItemName,#acallNum2,#acallNum").text(Cnc.Common.recource.user.staffName);
						$("#stuffPhone").text(Cnc.Common.recource.user.mobileNum);
						
						if(Cnc.Common.recource.user.faceImage){
							$("#user_photo,#img_acall,#img_acall2").find("img").attr("src",unescape(Cnc.Common.recource.user.faceImage)).show();
							$("#user_photo,#iuser_acall,#div_acall2").find("i").hide();
						}
						authority();
					}
				}
			});
		}
	}
		
	
	
	$(document).mousedown(function(event){
		$("div.listview .list-group-item.active button.pop-number").removeClass("active");
    	if(!$(event.target).hasClass("pop-number")){
    		$("div.popover.pop-number").hide();
    	}
    });
});
/*

Common - Ajax request
-----------------------------------------------

*/
Crypto.setRSAPublicKey("96882218394188644412948371128950497316988669042955310483312233871346521989162781335950366253239556038017595089945150559663347298675294176810061756014319964351910198854019287916523068982603608268314539028314743622240324564105254079904445484175331539491289199358370665301164518143393139101791868727267883813561");
function ajax(method, param) {
	var cipher  = Crypto.generateCipher();
	
	var defaultParam = {
		param:{},
		safe:false,
		data:{
			token:Cnc.Common.recource.user.accessToken,
			key:"web",
			secret:"web",
			format:"jsonp"
		},
		success:function(){},
		error:function(){}
	};
	$.extend(true, defaultParam, param);
	
	if(defaultParam.safe){
		defaultParam.data = {
			encryptData:encodeURIComponent(cipher.encrypt($.param(defaultParam.data))),
			encryptSource:"javascript"
		};
	}
	
	$.ajax({
		type: "get",
		data:defaultParam.data,
		async:defaultParam.async,
		url: Cnc.Common.recource.requestUrl + method,
		dataType: "jsonp",
		jsonp: "callback",
		success: function(result){
			if(param.safe){
				result = eval("("+decodeURIComponent(cipher.decrypt(result.result))+")");
			}
			if(result && result.executeResult && result.executeResult.error == 13){
				var cnc_last_account = $.cookie("cnc_last_account");
				if(cnc_last_account){
					cnc_last_account = eval("("+cnc_last_account+")");
					cnc_last_account.autoLogin = false;
					delete cnc_last_account.token;
					$.cookie("cnc_last_account", $.json2Str(cnc_last_account), { expires: 7 });
				}
				alert("用户无效或已失效,请重新登录");
				window.location.href = "login.html";
			}
			if(defaultParam.success)
				defaultParam.success(result, defaultParam.param);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			if(defaultParam.error)
				defaultParam.error(XMLHttpRequest, textStatus, errorThrown, defaultParam.param);
		}
	});
}

/*

Common - Date format
-----------------------------------------------

*/
Date.prototype.format = function(format) {
    var date = {
           "M+": this.getMonth() + 1,
           "d+": this.getDate(),
           "h+": this.getHours()%12 == 0 ? 12 : this.getHours()%12,
           "H+": this.getHours(),
           "m+": this.getMinutes(),
           "s+": this.getSeconds(),
           "q+": Math.floor((this.getMonth() + 3) / 3),
           "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
           format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
           if (new RegExp("(" + k + ")").test(format)) {
                  format = format.replace(RegExp.$1, RegExp.$1.length == 1
                         ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
           }
    }
    return format;
};

/*

Page - jQuery ConfUser PageSet Plugin
-----------------------------------------------

*/
(function ($) {
    $.fn.pageSet = function(pageView,queryFunction,param){
    	$(this).css("text-align","center").find("*").remove();
    	pageView = pageView.pageView;
    	if(!pageView)
    		return;
    	var pageCount = parseInt(pageView.pageCount);//总页数
    	var page = parseInt(pageView.page);//当前页
    	var rowCount = pageView.rowCount;
    	if(rowCount == 0){
    		return;
    	}
    	function queryByPage(event,originalEvent,type,page){
    		queryFunction(param,page);
    	}
    	var options = {
	        size:"small",
	        bootstrapMajorVersion:3,
	        currentPage:page,
	        numberOfPages:5,
	        totalPages:pageCount,
	        onPageClicked:queryByPage
	    };
    	$(this).css("height","30px");
    	$(this).append("<div class='page_num'><ul></ul></div><div class='page_info' style='float:right;margin-top:-35px;'><span>&nbsp;共<span class='count'></span>条记录,&nbsp;共<span class='page'></span>页&nbsp;</span></div>");
    	$(this).find("ul").bootstrapPaginator(options);
    	$(this).find(".count").html(pageView.rowCount);
    	$(this).find(".page").html(pageView.pageCount);
	};
})(jQuery);

/*

ListView - jQuery ConfUser List Plugin
-----------------------------------------------

*/

(function($) {
	function ListView(target, option) {//相当于类
		this.options = option;
		this.container = $(target);
		this.listHeard = null;
		this.listBody = null;
		this.parent = null;
		this.init();//初始化
	};
	
	ListView.prototype.filter = function(keyword){
		this.setData(this.options.filter(keyword, this.options.dataResult), true);
		$.each(this.listHeard.find(":checkbox"),function(){
			this.checked = false;
		});
	};
	
	ListView.prototype.setData = function(dataResult, isTemp) {
		var $this = this;
		if($this.options.scroll){
			$this.listBody.find("div.mCSB_container *").remove();
		}else{
			$this.listBody.find("*").remove();
		}
		var bodyView = $("<table class='table table-hover listBody'></table>");
		var defaultView = $("<table class='table listDefault'></table>").html($this.options.defaultView($this)).hide();
		
		if(dataResult && dataResult.length > 0){
			for (var key in dataResult) {
				var result = dataResult[key];
				if(!result)
					continue;
				result["indexKey"] = key;
				bodyView.append($this.options.createItem($this, result));
			}
		}else{
			defaultView.show();
			bodyView.hide();
		}
		
		if($this.options.scroll){
			$this.listBody.find("div.mCSB_container").append(defaultView).append(bodyView);
			$this.checkScroll();
		}else{
			$this.listBody.append(defaultView).append(bodyView);
		}
		$this.hideLoading();
		if(!isTemp)
			$this.options.dataResult = dataResult;
	};
	
	ListView.prototype.addItems = function(results){
		this.listBody.find("table.listDefault").hide();
		this.listBody.find("table.listBody").show();
		for ( var key in results) {
			var result = results[key];
			if(!result)
				continue;
			result["indexKey"] = this.options.dataResult.push(result) - 1;
			this.listBody.find("table.listBody").append(this.options.createItem(this, result));
			
		}
		if(this.options.scroll)
			this.checkScroll();
	};
	
	ListView.prototype.delItems = function(indexKeys){
		this.options.dataResult[indexKeys] = null;
		/*for ( var key in indexKeys){
			var index = indexKeys[key];
			this.options.dataResult.splice(index, 1);
		}*/
		if(this.options.scroll)
			this.checkScroll();
	};
	
	ListView.prototype.loading = function(){
		this.listBody.proAlert("show");
	};
	ListView.prototype.hideLoading = function(){
		this.listBody.proAlert("hide");
	};
	
	
	
	
	ListView.prototype.setHeight = function(height) {
		this.container.height(height);
		this.listBody.height(height - 38);
		this.checkScroll();
	};
	
	ListView.prototype.checkScroll = function(){
		if(this.options.scroll)
			this.listBody.mCustomScrollbar("update");
	};
	
	ListView.prototype.scrollTo = function(position){
		if(this.options.scroll)
			this.listBody.mCustomScrollbar("scrollTo", position);
	};
	
	ListView.prototype.init = function() {
		this.parent = this.options.parent;
		this.listHeard = $("<table class='table listHeard' style='margin:0'><thead></thead></table>");
		var listHeard = "<tr>";
		for ( var key in this.options.module) {
			var result = this.options.module[key];
			listHeard += "<td name ='"+key+"' width='"+result.width +"'>"+result.name+"</td>";
		}
		listHeard += "</tr>";
		this.listHeard.html(listHeard).find("td").bind("click", this, this.options.onHeardClick);
		
		this.listBody = $("<div></div>").css({
			"max-height":this.options.maxHeight - 38,
			height:this.options.height - 38
		}).proAlert({icon:"fa-spinner fa-spin",modal:true});
		if(this.options.scroll){
			this.listBody.mCustomScrollbar({
				scrollInertia:0,
				mouseWheelPixels:30,
				advanced:{
					autoScrollOnFocus:false
				}
			});
		}
		
		this.container.addClass("listview").css({
			"max-height":this.options.maxHeight,
			height:this.options.height
		}).append(this.listHeard).append(this.listBody);
		this.setData(this.options.dataResult);
	};

	ListView.defaultOption = {
		parent:null,
		height:"auto",
		maxHeight:"auto",
		scroll:true,
		module:[],
		filter:function(keyword, dataResult){return dataResult;},
		onHeardClick:function($this, event){},
		createItem:function($this, result){
			var item = "<tr id='"+ result.contactId+"'>";
			for ( var key in $this.options.module) {
				var m =  $this.options.module[key];
				item += "<td name ='"+m.key+"' width='"+m.width +"'>"+result[m.key]+"</td>";
			}
			item += "</tr>";
			return item;
		},
		defaultView:function($this){
			return "<tr><td style='text-aline:center;'>没有相关数据</td></tr>";
		},
		dataResult:[]
	};
	
	$.fn.listview = function(option, param) {//相当于构造方法
		
		 
		return this.each(function() {//遍历
			var $this   = $(this);
			var data    = $this.data('cnc.listview');
			var options = typeof option == 'object' && option;
			
			options = $.extend({}, ListView.defaultOption, $this.data(), options);
			
			if (!data) $this.data('cnc.listview', (data = new ListView(this, options)));
			if (typeof option == 'string') data[option](param);
		});
	};
	
	$.fn.listview.Constructor = ListView;
})(jQuery);

/*

TreeView - jQuery List Plugin
-----------------------------------------------

*/

(function($) {
	function TreeView(target, option) {
		this.container = $(target);
		this.options = option;
		this.groups = {};
		this.init();
	};

	TreeView.prototype.setData = function(dataResult) {
		var $this = this;
		if(!$this.mCSB_container){
			$this.mCSB_container = $this.container.find("div.mCSB_container");
		}
		$this.mCSB_container.find("*").remove();
		$this.groups = {};
		
		if(!dataResult)
			return;
		
		for(var key in dataResult) {
			var result = dataResult[key];
			if(!result)
				continue;
			
			var group = $("<div class='panel panel-default'/>");
			var item = $("<div/>");
			item.listview({
				parent:$this,
				scroll:false,
				dataResult:result.items,
				createItem:$this.options.createItem,
				defaultView:function($this){
					return "";
				}
			});
			$this.mCSB_container.append(group.append($this.options.createHeard($this, group, result)).append(item));
			$this.groups[result.groupId] = group;
		}
		$this.checkScroll();
		$this.hideLoading();
		$this.options.dataResult = dataResult;
	};
	
	TreeView.prototype.loading = function(){
		this.container.proAlert("show");
	};
	
	TreeView.prototype.hideLoading = function(){
		this.container.proAlert("hide");
	};
	
	TreeView.prototype.addGroups = function(results){
		for ( var key in results) {
			var result = results[key];
			var group = $("<div class='panel panel-default'/>");
			this.mCSB_container.append(group.append(this.options.createHeard(this, group, result)));
		}
		this.checkScroll();
	};
	
	TreeView.prototype.addItems = function(groupId, results){
		this.groups[groupId].find("div.listview").listview("addItems", results);
	};
	
	TreeView.prototype.checkScroll = function(){
		this.container.mCustomScrollbar("update");
	};
	
	TreeView.prototype.scrollTo = function(position){
		this.container.mCustomScrollbar("scrollTo", position);
	};
	
	
	TreeView.prototype.init = function() {
		var $this = this;
		$this.container.addClass("treeview").css({
			height:$this.options.height,
			width:$this.options.width
		}).proAlert({icon:"fa-spinner fa-spin",modal:true}).mCustomScrollbar({
			scrollInertia:0,
			mouseWheelPixels:30,
			advanced:{
				autoScrollOnFocus:false
			}
		});
		$this.setData($this.options.dataResult);
	};
	
	$.fn.treeview = function(option, param) {
		TreeView.defaultOption = {
			height:"auto",
			width:"auto",
			createHeard:function($this, group, result){
				var groupHeard = $("<a class='list-group-item' />");
				groupHeard.html("<span class='badge'>"+result.items.length+"</span>" +
						"<div style='max-width:"+($this.options.width-80)+"px;float:left' class='text-overflow'><i class='fa fa-caret-right'></i> "+result.groupName+"</div>&nbsp;").
				click(function(event){
					$this.mCSB_container.find("td.list-group-item.active").removeClass("active");
					if(group.hasClass("active")){
						group.removeClass("active");
					} else {
						group.addClass("active");
					}
					$this.checkScroll();
				});
				return groupHeard;
			},
			createItem:function(){},
			dataResult:null
		};
		 
		return this.each(function() {
			var $this   = $(this);
			var data    = $this.data('cnc.treeview');
			var options = typeof option == 'object' && option;
			
			options = $.extend({}, TreeView.defaultOption, $this.data(), options);
			
			if (!data) $this.data('cnc.treeview', (data = new TreeView(this, options)));
			if (typeof option == 'string') data[option](param);
		});
	};
	
	$.fn.treeview.Constructor = TreeView;
})(jQuery);







/*

ProgressAlert - jQuery Alert Plugin
-----------------------------------------------

*/

(function($) {
	function ProgressAlert(target, option) {
		this.el = $(target);
	    this.options  = option;
		this.init();
	};

	var icon = {
		primary:"fa-question-circle",
		info:"fa-info-circle",
		success:"fa-check-circle",
		warning:"fa-warning",
		danger:"fa-exclamation-circle"
	};
	ProgressAlert.prototype.init = function(){
		this.alert = $("<div class='alert alert-"+this.options.alert+" proAlert' style='"+this.options.style+"'>"+
				"<i class='fa "+(!this.options.icon?icon[this.options.alert]:this.options.icon)+" fa-lg'></i> "+ this.options.msg +
			"</div>");
		$("body").append(this.alert);
		
		if(this.options.modal){
			this.modal = $("<div class='alertModal'/>");
			$("body").append(this.modal);
		}
		if(this.options.delay != 0){
			this.show(this.options.msg);
			this.destroy();
		}
	};
	
	ProgressAlert.prototype.show = function(){
		var pos = {top: this.el.offset().top + this.el[0].offsetHeight/ 2 - parseInt(this.alert.css("height")) / 2,   left: this.el.offset().left + this.el[0].offsetWidth / 2 - parseInt(this.alert.css("width")) / 2  };
		this.alert.css({top:pos.top,left:pos.left}).show();
		if(this.options.modal){
			this.modal.height(this.el.height()).width(this.el.width()).css({top:this.el.offset().top,left:this.el.offset().left}).show();
		}
	};
	
	ProgressAlert.prototype.destroy = function(){
		$this = this;
		this.alert.fadeOut(this.options.delay,function(){
			$(this).remove();
			$this.el.removeData('cnc.proAlert');
		});
		if(this.options.modal){
			this.modal.fadeOut(this.options.delay,function(){
				$(this).remove();
				$this.el.removeData('cnc.proAlert');
			});
		}
	};
	
	ProgressAlert.prototype.hide = function(){
		this.alert.hide();
		if(this.options.modal){
			this.modal.hide();
		}
	};

	$.fn.proAlert = function(option) {
		ProgressAlert.defaultOption = {
			alert:"info",
			icon:"",
			modal:false,
			delay:0,
			msg:"",
			style:""
		};
		
		return this.each(function() {
			var $this   = $(this);
			var data    = $this.data('cnc.proAlert');
			var options = typeof option == 'object' && option;
			
			options = $.extend({}, ProgressAlert.defaultOption, $this.data(), options);
			
			if (!data) $this.data('cnc.proAlert', (data = new ProgressAlert(this, options)));
			if (typeof option == 'string') data[option]();
		});
	};
})(jQuery);


$.widget("custom.catcomplete", $.ui.autocomplete, {
	options:{
		renderItem:function(ul, item) {
		  return $("<li>")
		    .attr("data-value", item.value)
		    .append($("<a>").text( item.label ))
		    .appendTo(ul);
		},
		autoClose:true,
		category:true
	},
	_create:function() {
		$.ui.autocomplete.prototype._create.apply(this);
		this.scrollDiv = this.menu.element.css("float","left").wrap("<div class='ui-autocomplete-scroll' style='position:absolute;'>")
		.parent().append("<ul style='clear:both'></ul>");
		this.scrollDiv.position( $.extend({
			of: this.element
		}, this.options.position));
		
		this.scrollDiv.mCustomScrollbar({
			scrollInertia:0,
			advanced:{
				autoScrollOnFocus:false
			}
		}).hide();
	},
	_renderItem: function(ul, item) {
		return this.options.renderItem(ul, item);
	},
    _renderMenu: function( ul, items ) {
    	
    	ul.addClass("dropdown-menu");
    	var that = this,
        currentCategory = "";
    	$.each( items, function( index, item ) {
        if ( item.category != currentCategory ) {
        	if(that.options.category){
        	ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
	          currentCategory = item.category;
	        }

    	}
	        that._renderItemData( ul, item );
    	});
    },
    __response: function( content ) {
		if ( content ) {
			content = this._normalize( content );
		}
		this._trigger( "response", null, { content: content } );
		if ( !this.options.disabled && content && !this.cancelSearch ) {
			this._suggest( content );
			this._trigger( "open" );
			if(!content.length && !this.options.autoClose){
				this.menu.element.append( "<li class='ui-menu-item' role='presentation'><a>没有相关内容</a></li>" );
			}
		} else {
			// use ._close() instead of .close() so we don't cancel future searches
			this._close();
		}
	},
	_suggest: function( items ) {
		var ul = this.menu.element.empty();
		this._renderMenu( ul, items );
		this.isNewMenu = true;
		this.menu.refresh();

		// size and position menu
		ul.show();
		
		this._resizeMenu();
		/*ul.position( $.extend({
			of: this.element
		}, this.options.position ));*/
	
		if ( this.options.autoFocus ) {
			this.menu.next();
		}
		if(items.length > 0){
			this.scrollDiv.show().mCustomScrollbar("update");
			this.scrollDiv.position( $.extend({
				of: this.element
			}, this.options.position));
		}else if(this.options.autoClose){
			this.scrollDiv.hide();
		}
	},
    _close: function( event ) {
		if ( this.menu.element.is( ":visible" ) && (this.options.autoClose?true:this.element[0].value.length < 1)) {
			this.menu.element.hide();
			this.scrollDiv.hide();
			this.menu.blur();
			this.isNewMenu = true;
			this._trigger( "close", event );
		}
	}
  });
/*

ConfirAlert - jQuery Confirm Plugin
-----------------------------------------------

*/
$.extend({
	conAlert:function(option){
		var defaultOption = {
			title:"提示",
			backdrop:"static",
			context:"",
			keyboard:true,
			width:400,
			zIndex:1040,
			callback:function(){}
		};
		var options = $.extend({}, defaultOption, option);
		
		var conAlert = $("<div class='modal fade' style='overflow:hidden;z-index:"+options.zIndex+"'>" +
						"<div class='modal-dialog' style='width:"+options.width+"px'>" +
							"<div class='modal-content'>" +
								"<div class='modal-header'>" +
									"<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>" +
									"<h4 class='modal-title'>"+options.title+"</h4>" +
								"</div>" +
								"<div class='modal-body' style='word-break:break-all;break-word:break-word;'>" +
								"<i class='fa fa-question-circle fa-lg'></i> "+options.context +
								"</div>" +
								"<div class='modal-footer'>" +
									"<button name='false' type='button' class='btn btn-default' data-dismiss='modal'>取消</button>" +
									"<button name='true' type='button' class='btn btn-primary' data-dismiss='modal'>确定</button>" +
								"</div>" +
							"</div>" +
						"</div>" +
					"</div>");
		conAlert.find(".modal-footer button").click(function(){
			options.callback(this.name === "true");
		});
		$("body").append(conAlert);
		
		conAlert.modal({backdrop:options.backdrop, keyboard:options.keyboard}).on('hidden.bs.modal', function (e) {
			$(this).remove();
		});
	},
	singlePop:function(el, target, method, dataResult){
		var pos = null;
		if($(target).offset().top > 500){
			pos = { top: $(target).offset().top - parseInt(el.css("height")),   left: $(target).offset().left + $(target)[0].offsetWidth / 2 - 94 / 2  };
			el.removeClass("bottom").addClass("top");
		}else{
			pos = { top: $(target).offset().top + $(target)[0].offsetHeight,   left: $(target).offset().left + $(target)[0].offsetWidth / 2 - 94 / 2  };
			el.removeClass("top").addClass("bottom");
		}
		el.animate({top:pos.top,left:pos.left}, 200)[method](200);
		
		el.find("button").each(function(){
			var type = this.name.replace("btn_","")=="ttNum"?"TT：":(this.name.replace("btn_","")=="telNum"?"固话：":"手机：");
			$(this).removeClass("disabled").attr("title", type+dataResult[this.name.replace("btn_","")]);
			if(!dataResult[this.name.replace("btn_","")]){
				$(this).addClass("disabled");
			}
		}).unbind("click").click(function(){
			el.hide();
			$.popClick($(target)[0].name, dataResult, this.name.replace("btn_",""));
		});
	},
	popClick:function(method, result, numType){
		if(method.indexOf("launchCall") != -1){
			rightNavMove(1);
			$("#text_callNumber").val(result[numType]);
		}else{
			addConferenceFromContacts(result,numType);
		}
	},
	toDataView:function(dataModule){
		var dataView = dataModule.dataResult.dataView.result;
		var dataTreeView = [];
		var dataListView = [];
		var dataSearchView = [];
		
		for ( var key in dataView) {
			var data = dataView[key];
			data.itemId = data[dataModule.itemId];
			data.itemName = data[dataModule.itemName];
			data.groupId=data[dataModule.groupId];
			data.groupName=data[dataModule.groupName];
			
			var result = dataTreeView[data[dataModule.groupId]];
			if(!result){
				result = {
					groupId:data[dataModule.groupId],
					groupName:data[dataModule.groupName],
					items:data[dataModule.itemId]?[data]:[]
				};
				dataTreeView[data[dataModule.groupId]] = result;
				if(data[dataModule.itemId])
					dataListView.push(data);
			}else{
				if(data[dataModule.itemId]){
					result.items.push(data);
					dataListView.push(data);
				}
			}
			
			if(data[dataModule.itemId]){
				if(data.mobileNum && data.mobileNum != ""){
					dataSearchView.push({label:data.itemName, value:data.mobileNum, category:"手机", faceImage:data.faceImage});
				}
				if(data.telNum && data.telNum != ""){
					dataSearchView.push({label:data.itemName, value:data.telNum, category:"固话", faceImage:data.faceImage});
				}
				if(data.ttNum && data.ttNum != ""){
					dataSearchView.push({label:data.itemName, value:data.ttNum, category:"TT", faceImage:data.faceImage});
				}
			}
		}
		dataTreeView = dataTreeView.concat(dataTreeView.slice(0, 1));
		return {
			dataTreeView:dataTreeView.slice(1, dataTreeView.length),
			dataListView:dataListView,
			dataSearchView:dataSearchView
		};
	},
	getUrlData:function(){
		var dataString = window.location.href.split("?")[1];
		var user = new Object();
		if(dataString){
			dataString = decodeURI(dataString);
			var dataArray = new Array();
			dataArray = dataString.split("&");
			 
			for(var key in dataArray){
				var data = dataArray[key].split("=");
				user[data[0]] = data[1];
			}
		}
		return user;
	},
	jsonArr2Str:function(jsonArray){ 
		var JsonArrayString = "[ "; 
		for(var i=0;i<jsonArray.length;i++){ 
			JsonArrayString=JsonArrayString+$.json2Str(jsonArray[i])+","; 
		} 
		JsonArrayString = JsonArrayString.substring(0,JsonArrayString.length-1)+"]"; 
		return JsonArrayString; 
	} ,
	json2Str:function(o){
		var arr = []; 
		var fmt = function(s) { 
			if (typeof s == 'object' && s != null) 
				return $.json2Str(s); 
			return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; 
		};
		for (var i in o)
			arr.push("'" + i + "':" + fmt(o[i])); 
		return '{' + arr.join(',') + '}'; 
	}
});

function getPhoneType(phone) {
	var type = -1;
	if(/^(13[0-9]|15[0-9]|18[0-9]|14[57])[0-9]{8}$/.test(phone)) {
		type = 4;
	} else if(phone.length >=10 && /^0(([1-2]\d)|[4-9]\d{2})?[2-8]\d{5,7}$/.test(phone)) {
		type = 3;
	} else if(phone.charAt(0) == "2" && phone.length == 8) {
		type = 2;
	}
	
	return type;
}
function getUserInfo(number) {
	var dataResult = $.extend({},$("#treeview_orgUser").data("cnc.treeview").options.dataResult, $("#treeview_contactUser").data("cnc.treeview").options.dataResult);
	for ( var key in dataResult) {
		var items = dataResult[key].items;
		for(var index in items) {
			var user = items[index];
			if(user.staffId == number || user.mobileNum == number || user.telNum == number || user.ttNum == number){
				return {
					itemName:user.staffName?user.staffName:user.contName,
					faceImage:user.faceImage,
					number:number
				};
			}
		}
	}
	return {
		itemName:number,
		faceImage:null,
		number:number
	};
}
var cb = '^&*(';
var t = function(e, t) {
    return e << t | e >>> 32 - t;
}, n = function(e, t) {
    var n, r, i, s, o;
    return i = e & 2147483648, s = t & 2147483648, n = e & 1073741824, r = t & 1073741824, o = (e & 1073741823) + (t & 1073741823), n & r ? o ^ 2147483648 ^ i ^ s : n | r ? o & 1073741824 ? o ^ 3221225472 ^ i ^ s : o ^ 1073741824 ^ i ^ s : o ^ i ^ s;
}, r = function(e, t, n) {
    return e & t | ~e & n;
}, i = function(e, t, n) {
    return e & n | t & ~n;
}, s = function(e, t, n) {
    return e ^ t ^ n;
}, o = function(e, t, n) {
    return t ^ (e | ~n);
}, u = function(e, i, s, o, u, a, f) {
    return e = n(e, n(n(r(i, s, o), u), f)), n(t(e, a), i);
}, a = function(e, r, s, o, u, a, f) {
    return e = n(e, n(n(i(r, s, o), u), f)), n(t(e, a), r);
}, f = function(e, r, i, o, u, a, f) {
    return e = n(e, n(n(s(r, i, o), u), f)), n(t(e, a), r);
}, l = function(e, r, i, s, u, a, f) {
    return e = n(e, n(n(o(r, i, s), u), f)), n(t(e, a), r);
}, c = function(e) {
    var t, n = e.length, r = n + 8, i = (r - r % 64) / 64, s = (i + 1) * 16, o = Array(s - 1), u = 0, a = 0;
    while (a < n)
        t = (a - a % 4) / 4, u = a % 4 * 8, o[t] = o[t] | e.charCodeAt(a) << u, a++;
    return t = (a - a % 4) / 4, u = a % 4 * 8, o[t] = o[t] | 128 << u, o[s - 2] = n << 3, o[s - 1] = n >>> 29, o;
}, h = function(e) {
    var t = '', n = '', r, i;
    for (i = 0; i <= 3; i++)
        r = e >>> i * 8 & 255, n = '0' + r.toString(16), t += n.substr(n.length - 2, 2);
    return t;
}, p = function(e) {
    e = e.replace(/\x0d\x0a/g, '\n');
    var t = '';
    for (var n = 0; n < e.length; n++) {
        var r = e.charCodeAt(n);
        r < 128 ? t += String.fromCharCode(r) : r > 127 && r < 2048 ? (t += String.fromCharCode(r >> 6 | 192), t += String.fromCharCode(r & 63 | 128)) : (t += String.fromCharCode(r >> 12 | 224), t += String.fromCharCode(r >> 6 & 63 | 128), t += String.fromCharCode(r & 63 | 128));
    }
    return t;
};
function token(e) {
    var t = Array();
    e += cb;
    var r, i, s, o, d, v, m, g, y, b = 7, w = 12, E = 17, S = 22, x = 5, T = 9, N = 14, C = 20, k = 4, L = 11, A = 16, O = 23, M = 6, _ = 10, D = 15, P = 21;
    e = p(e), t = c(e), v = 1732584193, m = 4023233417, g = 2562383102, y = 271733878;
    for (r = 0; r < t.length; r += 16)
        i = v, s = m, o = g, d = y, v = u(v, m, g, y, t[r + 0], b, 3614090360), y = u(y, v, m, g, t[r + 1], w, 3905402710), g = u(g, y, v, m, t[r + 2], E, 606105819), m = u(m, g, y, v, t[r + 3], S, 3250441966), v = u(v, m, g, y, t[r + 4], b, 4118548399), y = u(y, v, m, g, t[r + 5], w, 1200080426), g = u(g, y, v, m, t[r + 6], E, 2821735955), m = u(m, g, y, v, t[r + 7], S, 4249261313), v = u(v, m, g, y, t[r + 8], b, 1770035416), y = u(y, v, m, g, t[r + 9], w, 2336552879), g = u(g, y, v, m, t[r + 10], E, 4294925233), m = u(m, g, y, v, t[r + 11], S, 2304563134), v = u(v, m, g, y, t[r + 12], b, 1804603682), y = u(y, v, m, g, t[r + 13], w, 4254626195), g = u(g, y, v, m, t[r + 14], E, 2792965006), m = u(m, g, y, v, t[r + 15], S, 1236535329), v = a(v, m, g, y, t[r + 1], x, 4129170786), y = a(y, v, m, g, t[r + 6], T, 3225465664), g = a(g, y, v, m, t[r + 11], N, 643717713), m = a(m, g, y, v, t[r + 0], C, 3921069994), v = a(v, m, g, y, t[r + 5], x, 3593408605), y = a(y, v, m, g, t[r + 10], T, 38016083), g = a(g, y, v, m, t[r + 15], N, 3634488961), m = a(m, g, y, v, t[r + 4], C, 3889429448), v = a(v, m, g, y, t[r + 9], x, 568446438), y = a(y, v, m, g, t[r + 14], T, 3275163606), g = a(g, y, v, m, t[r + 3], N, 4107603335), m = a(m, g, y, v, t[r + 8], C, 1163531501), v = a(v, m, g, y, t[r + 13], x, 2850285829), y = a(y, v, m, g, t[r + 2], T, 4243563512), g = a(g, y, v, m, t[r + 7], N, 1735328473), m = a(m, g, y, v, t[r + 12], C, 2368359562), v = f(v, m, g, y, t[r + 5], k, 4294588738), y = f(y, v, m, g, t[r + 8], L, 2272392833), g = f(g, y, v, m, t[r + 11], A, 1839030562), m = f(m, g, y, v, t[r + 14], O, 4259657740), v = f(v, m, g, y, t[r + 1], k, 2763975236), y = f(y, v, m, g, t[r + 4], L, 1272893353), g = f(g, y, v, m, t[r + 7], A, 4139469664), m = f(m, g, y, v, t[r + 10], O, 3200236656), v = f(v, m, g, y, t[r + 13], k, 681279174), y = f(y, v, m, g, t[r + 0], L, 3936430074), g = f(g, y, v, m, t[r + 3], A, 3572445317), m = f(m, g, y, v, t[r + 6], O, 76029189), v = f(v, m, g, y, t[r + 9], k, 3654602809), y = f(y, v, m, g, t[r + 12], L, 3873151461), g = f(g, y, v, m, t[r + 15], A, 530742520), m = f(m, g, y, v, t[r + 2], O, 3299628645), v = l(v, m, g, y, t[r + 0], M, 4096336452), y = l(y, v, m, g, t[r + 7], _, 1126891415), g = l(g, y, v, m, t[r + 14], D, 2878612391), m = l(m, g, y, v, t[r + 5], P, 4237533241), v = l(v, m, g, y, t[r + 12], M, 1700485571), y = l(y, v, m, g, t[r + 3], _, 2399980690), g = l(g, y, v, m, t[r + 10], D, 4293915773), m = l(m, g, y, v, t[r + 1], P, 2240044497), v = l(v, m, g, y, t[r + 8], M, 1873313359), y = l(y, v, m, g, t[r + 15], _, 4264355552), g = l(g, y, v, m, t[r + 6], D, 2734768916), m = l(m, g, y, v, t[r + 13], P, 1309151649), v = l(v, m, g, y, t[r + 4], M, 4149444226), y = l(y, v, m, g, t[r + 11], _, 3174756917), g = l(g, y, v, m, t[r + 2], D, 718787259), m = l(m, g, y, v, t[r + 9], P, 3951481745), v = n(v, i), m = n(m, s), g = n(g, o), y = n(y, d);
    var H = h(v) + h(m) + h(g);
    return H.toLowerCase();
}
